<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#dialog_notes").dialog({autoOpen:false,modal:true});
	$(".more_click").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".addnotes_click").click(function(){
		$("#notes_id").val($(this).next().val());
		$("#dialog_notes").dialog("open");
	});
	$(".more_content").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$(".view").toggle(function(){
		$(this).parent().parent().next().show();
	},function(){
		$(this).parent().parent().next().hide();
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#multi_hold_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert("请选择订单！");
			return false;
		}
		if ( ! confirm('确定把所选的单“滞留”？'))
		{
			return false;
		}
		$("#multi_ids").val(ids);
		$("#multi_form").attr("action", "<?=url('Storage::FBA/MultiHold', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>").submit();
	});
	$("#multi_cancel_hold_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择订单！");
			return false;
		}
		if ( ! confirm('确定把所选的单“返回销售确认”？'))
		{
			return false;
		}
		$("#multi_ids").val(ids);
		$("#multi_form").attr("action", "<?=url('Storage::FBA/MultiToCheckOut')?>").submit();
	});
	$("#multi_to_sales_hold_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择订单！");
			return false;
		}
		$("#dialog_notes form").attr("action", "<?=url('Storage::FBA/MultiToSalesHold')?>");
		$("#notes_id").val(ids);
		$("#dialog_notes").dialog("open");
	});
	$("#multi_out_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择订单！");
			return false;
		}
		if ( ! confirm('确定把所选的单“出库”？'))
		{
			return false;
		}
		$("#multi_ids").val(ids);
		$("#multi_form").attr("action", "<?=url('Storage::FBA/MultiOut', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>").submit();
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>制单日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_make_time" value="<?=isset($_GET['begin_make_time']) ? $_GET['begin_make_time'] : ''?>" /> to
		<input type="text" class="datepicker" name="end_make_time" value="<?=isset($_GET['end_make_time']) ? $_GET['end_make_time'] : ''?>" />
	</td>
	<th>系统估重(g)</th>
	<td>
		<select name="weight_operator">
			<option value="">请选择..</option>
			<option value="=" <?if(isset($_GET['weight_operator'])&&$_GET['weight_operator']=='=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if(isset($_GET['weight_operator'])&&$_GET['weight_operator']=='>=')echo "selected='selected'"?>>&gt;=</option>
			<option value="<=" <?if(isset($_GET['weight_operator'])&&$_GET['weight_operator']=='<=')echo "selected='selected'"?>>&lt;=</option>
		</select>
		<input type="text" name="weight" value="<?=isset($_GET['weight']) ? $_GET['weight']:''?>" />
	</td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id">
			<option value=""></option>
			<?foreach ($shop as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && $_GET['shop_id']==$s['id']) echo "selected='selected'"?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
	<th>产品编号</th>
	<td><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>" /></td>
</tr>
<tr>
	<th>本地单号</th>
	<td><input type="text" name="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
	<th>网站单号</th>
	<td><input type="text" name="shop_order_number" value="<?=isset($_GET['shop_order_number']) ? $_GET['shop_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>买家ID</th>
	<td><input type="text" name="shop_buyer_id" value="<?=isset($_GET['shop_buyer_id']) ? $_GET['shop_buyer_id'] : ''?>" /></td>
	<th>买家全名</th>
	<td><input type="text" name="fullname" value="<?=isset($_GET['fullname']) ? $_GET['fullname'] : ''?>" /></td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
		<option value="">请选择..</option>
		<?foreach ($warehouse as $w):?>
		<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>邮寄方式</th>
	<td colspan="3">
		<table>
		<?foreach ($shipping_method as $sm):?>
		<tr>
			<th><strong><?=$sm['name']?>：</strong></th>
			<td style="padding: 1px;">
				<?foreach ($sm['children'] as $v):?>
				<label style="float: left;"><input type="checkbox" name="shipping_method[<?=$v['id']?>]" value="<?=$v['id']?>" <?if (isset($_GET['shipping_method']) && array_key_exists($v['id'], $_GET['shipping_method'])) echo "checked='checked'"?> /> <?=$v['name']?>&nbsp;</label>
				<?endforeach;?>
			</td>
		</tr>
		<?endforeach;?>
		</table>
	</td>
</tr>
<tr id="handle_status">
	<th>订单状态</th>
	<td colspan="3">
		<label><input type="checkbox" name="order_status[<?=Q::ini('custom_flag/sales_order_handle_status/assigned/value')?>]" value="<?=Q::ini('custom_flag/sales_order_handle_status/assigned/value')?>" <?if (isset($_GET['order_status']) &&  array_key_exists(Q::ini('custom_flag/sales_order_handle_status/assigned/value'), $_GET['order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/sales_order_handle_status/assigned/name')?></label>
		<label><input type="checkbox" name="order_status[<?=Q::ini('custom_flag/sales_order_handle_status/warehouse_hold/value')?>]" value="<?=Q::ini('custom_flag/sales_order_handle_status/warehouse_hold/value')?>" <?if (isset($_GET['order_status']) &&  array_key_exists(Q::ini('custom_flag/sales_order_handle_status/warehouse_hold/value'), $_GET['order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/sales_order_handle_status/warehouse_hold/name')?></label>
	</td>
</tr>
<tr>
	<th>提示标志</th>
	<td>
		<?foreach (Q::ini('custom_flag/sales_order_tips_flag') as $sotf):?>
		<label><input type="checkbox" name="wanted_edit[<?=$sotf['value']?>]" value="<?=$sotf['value']?>" <?if (isset($_GET['wanted_edit']) &&  array_key_exists($sotf['value'], $_GET['wanted_edit'])) echo "checked='checked'"?> /> <?=$sotf['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
	<tr>
		<th width="30"></th>
		<th width="100">本地单号</th>
		<th>网站/店铺</th>
		<th>网站单号</th>
		<th>买家ID</th>
		<th width="80">制单日期</th>
		<th>邮寄方式</th>
		<th>估重</th>
		<th width="110">系统状态</th>
		<th>店铺状态</th>
		<th>发货仓库</th>
		<th width="100">操作</th>
	</tr>
<?foreach ($sales_order as $so):?>
<tr <?if($so['warning']):?>style="background-color: #ff8800;"<?endif;?>>
	<td><input type="checkbox" value="<?=$so['id']?>" /></td>
	<td><?=$so['number']?></td>
	<td><?=$so['shop_name']?></td>
	<td><?=$so['shop_order_number']?></td>
	<td><?=$so['shop_buyer_id']?></td>
	<td title="销售时间：<?=$so['sales_time'] ? $so['sales_time'] : ''?> <?=$so['sales_user_name']?> 
制单时间：<?=$so['make_time'] ? $so['make_time'] : ''?> <?=$so['make_user_name']?>   
销售确认：<?=$so['checkout_time'] ? $so['checkout_time'] : ''?> <?=$so['checkout_user_name']?>"><?=substr($so['make_time'], 0, 10)?></td>
	<td><?=$so['shipping_method_name']?></td>
	<td><?=sprintf('%.2f',$so['estimated_weight'])?>g</td>
	<td>
		<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $so['handle_status'], 'name')?>
		<span class="<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $so['handle_status'], 'icon_class')?>"></span>
		<?if ($so['has_sales_notes']):?><span class="sales_notes_icon"></span><?endif;?>
		<?if ($so['has_warehouse_notes']):?><span class="warehouse_notes_icon"></span><?endif;?>
		<?foreach (Q::ini('custom_flag/sales_order_synchronous_flag') as $sf):?>
		<?if($so['synchronous_flag'] == $sf['value']):?><div><font color="green"><?=$sf['name']?></font><span class="express_icon"></span></div><?endif;?>
		<?endforeach;?>
		<?if ($so['tips_flag']):?><div><font color="red"><?=Helper_BSS_Normal::getIniOne('sales_order_tips_flag', 'value', $so['tips_flag'], 'name')?></font><span class="<?=Helper_BSS_Normal::getIniOne('sales_order_tips_flag', 'value', $so['tips_flag'], 'icon_class')?>"></span></div><?endif;?>
	</td>
	<td><?=$so['api_status']?></td>
	<td><?=$so['warehouse_name']?></td>
	<td>
		<a class="view" href="javascript:void(0);">查看</a>
		<a href="javascript:void(0);" class="addnotes_click">添加备注</a>
		<input type="hidden" value="<?=$so['id']?>" />
	</td>
</tr>
<tr class="detail" style="display: none;">
	<td colspan="25">
		<table width="100%" class="list_table">
			<tr>
				<th width="15%">仓库</th>
				<td width="35%"><?=$so['warehouse_name']?></td>
				<th width="15%">制单人</th>
				<td width="35%"><?=$so['make_user_name']?></td>
			</tr>
			<tr>
				<th width="15%">发货类型</th>
				<td width="35%"><?=Helper_BSS_Normal::getIniOne('sales_order_send_method', 'value', $so['send_method'], 'name')?></td>
				<th>支付方式</th>
				<td><?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $so['payment_method'], 'name')?></td>
			</tr>
			<tr>
				<th>邮寄方式</th>
				<td><?=$so['shipping_method_name']?></td>
				<th>交易号</th>
				<td><?=$so['transaction_id']?></td>
			</tr>
			<tr>
				<th>买家姓名</th>
				<td><?=$so['fullname']?></td>
				<th>买家Email</th>
				<td><?=$so['email']?></td>
			</tr>
			<tr>
				<th>买家电话</th>
				<td><?=$so['phone']?></td>
				<th>收货地址1</th>
				<td><?=$so['street1']?></td>
			</tr>
			<tr>
				<th>收货地址2</th>
				<td><?=$so['street2']?></td>
				<th>城市</th>
				<td><?=$so['city']?></td>
			</tr>
			<tr>
				<th>州/省</th>
				<td><?=$so['state']?></td>
				<th>邮政编码</th>
				<td><?=$so['zip']?></td>
			</tr>
			<tr>
				<th>国家</th>
				<td><?=$so['country']?></td>
				<th>国家(中文)</th>
				<td><?=$so['country_cn']?></td>
			</tr>
			<tr>
				<th>运费</th>
				<td><?=$so['currency_symbol']?><?=sprintf('%.2f', $so['shipping_fee'])?></td>
				<th>折扣</th>
				<td><?=$so['currency_symbol']?><?=sprintf('%.2f', $so['discount'])?></td>
			</tr>
			<?if ($so['address_notes']):?>
			<tr>
				<th>地址备注</th>
				<td align="left" colspan="3"><?=$so['address_notes']?></td>
			</tr>
			<?endif;?>
			<?if ($so['order_notes']):?>
			<tr>
				<th>订单备注</th>
				<td align="left" colspan="3">
				<?foreach ($so['order_notes'] as $son):?>
				<p><?=$son['notes_name']?>(<?=$son['add_time']?>):<?=$son['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
			<?if ($so['sales_notes'] || $so['warehouse_notes']):?>
			<tr>
				<th>消息备注</th>
				<td align="left" colspan="3">
				<?foreach ($so['sales_notes'] as $ssn):?>
				<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
				<?endforeach;?>
				<?foreach ($so['warehouse_notes'] as $ssn):?>
				<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
			<?if ($so['customer_notes']):?>
			<tr>
				<th>客人备注</th>
				<td align="left" colspan="3">
				<?foreach($so['customer_notes'] as $scn):?>
				<p><?=$scn['notes']?></p>
				<?endforeach;?>
				</td>
			</tr>
			<?endif;?>
		</table>
		<div align="left"><strong>销售订单产品信息</strong></div>
		<table width="100%" class="list_table">
			<tr>
				<th>产品编号</th>
				<th>数量</th>
				<th>可用库存</th>
				<th>ShopItemId</th>
				<th>ShopTransactionId</th>
			</tr>
			<?$total_quantity = 0;?>
			<?foreach ($so['item'] as $soi):?>
			<?$total_quantity += $soi['quantity']?>
			<tr>
				<td>
					<?=$soi['number']?>
					<?if ($soi['pic_url']):?>
						<?$pretty_photo_number = 0;?>
						<?foreach ($soi['pic_url'] as $soip):?>
						<a rel="pretty_photo[<?=$soi['id']?>]" href="<?=$soip?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
						<?$pretty_photo_number = 1;?>
						<?endforeach;?>
					<?endif;?>
				</td>
				<td><?=$soi['quantity']?></td>
				<td><?=($soi['available_quantity']<$soi['quantity']) ? "<span class='red'>{$soi['available_quantity']}</span>" : $soi['available_quantity'] ?></td>
				<td><?=$soi['shop_item_id']?></td>
				<td><?=$soi['shop_transaction_id']?></td>
			</tr>
			<?endforeach;?>
			<tr>
				<td colspan="1">小计</td>
				<td><?=$total_quantity?></td>
				<td colspan="4"></td>
			</tr>
		</table>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td rowspan="10"><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td align="left">
		<input type="button" class="button" id="multi_hold_btn" value="仓库滞留" /> |
		取消仓库滞留： 
		<input type="button" class="button" id="multi_cancel_hold_btn" value="销售确认" />
		<input type="button" class="button" id="multi_to_sales_hold_btn" value="销售滞留" /> |
		<input type="button" class="button" id="multi_out_btn" value="转为出库" />
	</td>
</tr>
</table>
<div id="dialog_notes" title="填写备注">
<form method="post" action="<?=url('Storage::FBA/AddNotes')?>">
<input type="hidden" name="id" id="notes_id" value="" />
<textarea name="notes_content" rows="3" cols="30"></textarea>
<input type="submit" value="添加备注" class="button" />
</form>
</div>
<form id="multi_form" action="" method="post">
<input type="hidden" name="ids" id="multi_ids" />
</form>
<?php $this->_endblock(); ?> 